package com.xbongbong.saas.model;

import com.xbongbong.paas.domain.entity.StageLogEntity;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.saas.domain.entity.CustomerStageLogEntity;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/3/10 16:43
 * @since v1.0
 */
public interface CustomerStageLogModel {

    /**
     * 计算某些阶段的某些客户，在这些阶段的停留时长
     * @param corpid 公司id
     * @param customerIdIn 要查询的客户ids
     * @param stageCodeIn 要查询的阶段codes
     * @return java.util.Map<java.lang.String,java.lang.Double> 返回map，内部结构为：阶段code--该批客户在该阶段的平均停留时长
     * @author zcp
     * @date 2019/3/11 16:28
     * @since v1.0
     * @version v1.0
     */
    Map<String, Double> getAverageStayTime(String corpid, Set<Long> customerIdIn, List<String> stageCodeIn);

    /**
     * 获取当前阶段记录
     * @param customerId
     * @param corpid
     * @return
     */
    CustomerStageLogEntity getNowStageLog(Long customerId, String corpid, Long formId);

    /**
     * 当前阶段的停留时长
     *
     * @param corpid 公司id
     * @param customerId 客户id
     * @return
     * @throws
     * @author hongxiao
     * @date: 2019-04-16 14:54
     * @since v1.0
     * @version v1.0
     */
    String getAverageStayTime(String corpid, Long customerId, Long formId) throws XbbException;

    List<CustomerStageLogEntity> findEntitys(Map<String,Object> param);

    void save(CustomerStageLogEntity customerStageLogEntity);

    void insertBatch(List<CustomerStageLogEntity> customerStageLogEntity);
    Integer deleteByStageProcessIdAndDataIdIn(List<Long> dataIdIn, String corpid, Long formId, Long stageProcessId, Long stageId);
    void deleteEntitys(Map<String,Object> searchParam);

    CustomerStageLogEntity getByKey(Long id, String corpid);

    /**
     * 获取客户流失前的阶段
     */
    Map<Long, String> getCustomerLoseBeforeStage(String corpid, List<Long> customerIdIn, Map<String, String> stageCodeName);

    /**
     * 获取客户流失时间
     */
    Map<Long, Long> getCustomerLoseTime(String corpid, List<Long> customerIdIn);

    void updateBatch(List<CustomerStageLogEntity> updateList, String corpid) throws XbbException;

    void updateBatch4Script(List<CustomerStageLogEntity> updateList) throws XbbException;

    /**
     * 获取当前流失客户阶段日志
     * reasonId：流失原因
     */
    List<Long> getLoseCustomerList(Map<String,Object> param) throws XbbException;

    /**
     * 获取当前流失客户阶段分组统计
     */
    Map<String, Integer> getStageStatistic(Long formId, String corpid, List<Long> customerIdIn) throws XbbException;

    List<CustomerStageLogEntity> findStageLogWithoutStage();

    Integer deleteBatch(List<StageLogEntity> stageLogEntityList, String corpid);

    Integer getEntitysCount(Map<String, Object> param);

    /**
     * 根据dataId 查找当前数据所处阶段
     * @param corpid
     * @param formId
     * @param dataId
     * @return
     */
    CustomerStageLogEntity getIsNowStage(String corpid, Long formId, Long dataId);

    Long getAvgStayTime(String corpid, Long stageProcessId, Long stageId);

    List<Long> findUsedStageProcessId(String corpid, Long formId, List<Long> stageProcessIdIn);
}
